'use strict';

app.controller('changePswCtl', function($scope,$http,rest,$compile,$location,ngDialog,user,$state,$window,uiLoad,$rootScope,$ocLazyLoad,tipService) {

	$scope.params = {
        phone: user.get('phone'),
        PasswordType : 0
    };
    // $scope.phone = phone;
    $scope.isTransPasswordSet = user.get('isTransPasswordSet');
    $scope.$watch('oldPassword', function(newValue, oldValue) {
        $scope.params.oldPassword = newValue;
    })
    $scope.$watch('newPassword', function(newValue, oldValue) {
        $scope.params.newPassword = newValue;
    })
    $scope.$watch('comfirmedPassword', function(newValue, oldValue) {
        $scope.params.comfirmedPassword = newValue;
    })
	$scope.saveData = function() {
        if (!$scope.oldPassword) {
            tipService.show("body", {
                message: "请输入原密码",
                notice: "danger"
            }, 3);
            return;
        }
        if (!$scope.newPassword) {
            tipService.show("body", {
                message: "请输入新密码",
                notice: "danger"
            }, 3);
            return;
        }
        if (!$scope.comfirmedPassword) {
            tipService.show("body", {
                message: "请输入确认密码",
                notice: "danger"
            }, 3);
            return;
        }
		if ($scope.newPassword != $scope.comfirmedPassword) {
            tipService.show("body", {
                message: "两次密码输入不一致",
                notice: "danger"
            }, 3);
            return;
        }
        if ($scope.newPassword.length != 6) {
            tipService.show("body", {
                message: "密码应为 6 位",
                notice: "danger"
            }, 3);
            return;
        }
		rest.post({
            methodId: '5018',
            data: $scope.params,
            success: function(res) {
                if (res.code == 0) {
                    tipService.show("body", {
                        message: "密码修改成功"
                    }, 2);
                    console.log($scope.params);
                    $location.path('/app/houseOwner/list');
                } else {
                    tipService.show("body", {
                        message: "原密码输入错误!",
                        notice: "danger"
                    }, 3);
                }
            },
            error: function() {

            }
        })
	}
	$scope.backList = function() {
        $scope.params = {};
        $location.path('/app/houseOwner/list');
    }





});